package com.lfs.dingtalk.robot.servcie;

import com.dingtalk.open.app.api.callback.OpenDingTalkCallbackListener;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import shade.com.alibaba.fastjson2.JSON;

import java.util.List;
import java.util.Map;


/**
 * 长连接holder, 维护和钉钉开放平台外联网关的Stream长连接
 * @author dingtalk
 */
@Slf4j
public class PersistenceConnectionHolder {

    public static OpenDingTalkCallbackListener<CardCallbackRequest, CardCallbackResponse> yourListener = request -> {
            log.info("收到回调信息, {}", JSON.toJSONString(request));

            //your code is here

            //开发者根据自身业务需求，变更卡片内容，返回response
            CardCallbackResponse response = new CardCallbackResponse();
            return response;
        };
  

   /**
     * 卡片回调请求
     */
   @AllArgsConstructor
   @NoArgsConstructor
   @Data
    public static class CardCallbackRequest{

        /**
         * 回调类型,actionCallback
         */
        private String type;
        /**
         * 发起事件回调卡片的ID
         */
        private String outTrackId;
        /**
         * 回调内容,ActionCallbackContent的jsonString格式
         */
        private String content;
        /**
         * 卡片归属的企业id
         */
        private String corpId;
        /**
         * 用户userId
         */
        private String userId;

        /**
         * 回调按钮的内容信息
         */
        @AllArgsConstructor
        @NoArgsConstructor
        @Data
        public static class ActionCallbackContent {
            private PrivateCardActionData cardPrivateData;

            public static class PrivateCardActionData {
                //点击按钮的id
                private List<String> actionIds;

                //给按钮配置的额外参数
                private Map<String, Object> params;

            }
        }
    }
  
   /**
     * 卡片回调响应
     */
   @AllArgsConstructor
   @NoArgsConstructor
   @Data
    public static class CardCallbackResponse {

        //卡片公有数据
        private CardDataDTO cardData;

        //触发回调用户的私有数据
        private CardDataDTO userPrivateData;

       @AllArgsConstructor
       @NoArgsConstructor
       @Data
        public static class CardDataDTO{

            //卡片参数
            private Map<String, String> cardParamMap;
        }
    }
 
}